https://leetcode.cn/problems/unique-paths-iii/description/

class Solution {
public:
    int ret,m,n,srcx,srcy,countzore;
    bool check[21][21];
    int dx[4]={0,0,1,-1};
    int dy[4]={1,-1,0,0};

    void dfs(vector<vector<int>>& grid,int row,int col,int path)
    {
        if(grid[row][col]==2)
        {
            if(path==countzore+2)
                ret++;
            return ;
        }
        for(int i=0;i<4;i++)
        {
            int x=dx[i]+row,y=dy[i]+col;
            if(x>=0&&x<m && y>=0&&y<n && !check[x][y] && grid[x][y]!=-1)
            {
                check[x][y]=true;
                dfs(grid,x,y,path+1);
                //恢复现场
                check[x][y]=false;
            }
        }
    }
    int uniquePathsIII(vector<vector<int>>& grid) {
        m=grid.size(),n=grid[0].size();
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(!grid[i][j])
                    countzore++;
                else if(grid[i][j]==1)
                {
                    srcx=i,srcy=j;
                }
            }
        }
        check[srcx][srcy]=true;
        dfs(grid,srcx,srcy,1);
        return ret;
    }
};